import { request } from "../request";

const token = localStorage.getItem("token");

/**
 * 批量上传文件接口返回结构
 */
export interface UploadMultipleFilesRes {
    code: number;
    message: string;
    data: Record<string, unknown>;
    timestamp: Record<string, unknown>;
}

/**
 * 批量上传文件
 * @param params 上传参数，包含文件数组与文件夹名
 * @returns 上传结果
 */
export const uploadMultipleFilesAPI = async (params: {
    files: File[];
    folder: string;
}): Promise<UploadMultipleFilesRes> => {
    const { files, folder } = params;
    const token = localStorage.getItem("token");
    const formData = new FormData();
    formData.append("folder", folder);
    files.forEach(file => {
        formData.append("files", file); // 后端必须支持接收多个 files 字段
    });

    return request("/api/file/upload/multiple", {
        method: "post",
        data: formData,
        headers: {
            Authorization: `Bearer ${token}`
        }
    });
};
